import React, { Component } from 'react';
import ACTIONS from '../../../redux/action';
import { connect } from 'react-redux';

class DigitButton extends Component {
    state = {  } 
    // 渲染函数
    render() { 
    
        // 返回一个按钮，点击按钮时调用props中的add_digit方法，并传入props中的digit参数
        return <button onClick={() => this.props.add_digit(this.props.digit)}>
            {this.props.digit}
        </button>;
    }
}

const mapDispatchToProps = {
    add_digit: digit   => {
        return {
            type: ACTIONS.ADD_DIGIT,
            digit: digit
        }
            
    }
}
 
export default connect(null, mapDispatchToProps)(DigitButton);